package com.foreknow.demo13;

import com.foreknow.demo6.Emp;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class ListDemo {
    public static void main(String[] args) {
        //1. 创建一个List集合 <Integer>表示范型：用来约束集合中元素的类型   Integer[] arr = new Integer[10]
        List<Integer> list = new ArrayList<>();
        //2. 向集合中添加元素
        list.add(1);
        list.add(12);
        list.add(13);
        //3. 从集合中获取元素
        Integer i1 =  list.get(0);
        System.out.println(i1);
        System.out.println("---------------普通for循环------------------");
        //4. 遍历集合
        for (int i = 0;i<list.size();i++){
            System.out.println(list.get(i));
        }
        System.out.println("--------------foreach-------------------");
        for (Integer ii:list) {
            System.out.println(ii);
        }
        System.out.println("--------------迭代器 Iterator<E>接口-------------------");
        Iterator<Integer> it = list.iterator();
        while (it.hasNext()) {
            Integer ii = it.next();
            System.out.println(ii);
        }
    }
}
